package org.example;

import org.example.dao.ClazzDao;
import org.example.dao.ProductCategoryDao;
import org.example.dao.StudentDao;
import org.example.dao.UserDao;
import org.example.entity.Clazz;
import org.example.entity.ProductCategory;
import org.example.entity.Student;
import org.example.entity.User;
import org.example.jdbcOperator.page.Condition;
import org.example.jdbcOperator.page.Operator;
import org.example.jdbcOperator.page.Page;

import java.sql.SQLOutput;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void main(String[] args) {
//        User user = new User();
//        user.setId(5);
//        user.setName("am");
//        user.setPassword("222");
//        user.setBirthday(new Timestamp(System.currentTimeMillis()));
//        user.setUpdateTime(new Timestamp(System.currentTimeMillis()));
//        UserDao userDao = new UserDao();
//        System.out.println(userDao.findList(new Page(2, 5)));
//        userDao.findList(new Page(2, 5)).forEach(t -> System.out.println(t.getId()));

//        ProductCategory productCategory = new ProductCategory();
//        productCategory.setId(4);
//        productCategory.setProductCategoryId(11);
//        productCategory.setProductName("111");
//        ProductCategoryDao productCategoryDao = new ProductCategoryDao();
//        System.out.println(productCategoryDao.update(productCategory));
//        productCategoryDao.closeConnection();

//        Field[] declaredFields = User.class.getDeclaredFields();
//        for (Field declaredField : declaredFields) {
//            System.out.println(declaredField.getName());
//        }

//        Column annotation = User.class.getAnnotation(Column.class);
//        Field declaredField = null;
//        try {
//            declaredField = User.class.getDeclaredField("name");
//        } catch (NoSuchFieldException e) {
//            throw new RuntimeException(e);
//        }
//        Column annotation = declaredField.getAnnotation(Column.class);
//        System.out.println(annotation.primaryKey());
//        Table annotation1 = User.class.getAnnotation(Table.class);
//        System.out.println(annotation1.tableName());

//        Arrays.stream(User.class.getAnnotations()).forEach(x -> System.out.println(x.toString()));
//        System.out.println();

//        Page page = new Page(1, 10);
//        List<Integer> list = new ArrayList<>();
//        list.add(1);
//        list.add(4);
//        list.add(5);
////        page.getConditions().add(new Condition("name", "%a%", Operator.LIKE));
//        page.getConditions().add(new Condition("id", list, Operator.IN));
////        page.getConditions().add(new Condition("id", 5, Operator.EQ));
////        page.getConditions().add(new Condition("birthday", new Timestamp(1697467467000L), Operator.LTE));
//        UserDao userDao = new UserDao();
//        List<User> res = userDao.findList(page);
//        res.forEach(u -> System.out.println(u.getId() + " " + u.getName()));

//        UserDao userDao = new UserDao();
//        System.out.println(userDao.delete(28));

//        ClazzDao clazzDao = new ClazzDao();
//        List<Clazz> list = clazzDao.findList(new Page(1, 5));
//        list.forEach(x -> System.out.println(x.getName()));

//        StudentDao studentDao = new StudentDao();
//        List<Student> list = studentDao.findList(new Page(1, 5));
//        list.forEach(x -> System.out.println(x.getName()));

//        ClazzDao clazzDao = new ClazzDao();
//        Clazz clazz = clazzDao.find(1);
//        System.out.println(clazz.getName());
//        Student student = new Student();
//        student.setAge(6);
//        student.setName("6");
//        student.setSex(1);
//        student.setClazz(clazz);
//        StudentDao studentDao = new StudentDao();
//        studentDao.add(student);

//        StudentDao studentDao = new StudentDao();
//        List<Student> list = studentDao.findList(new Page(1, 5));
//        list.forEach(x -> System.out.println(x.getName() + ": " + x.getClazz().getName()));

        for (int i = 0; i < 100; i++) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    UserDao userDao = new UserDao();
                    userDao.findList(new Page(1, 10));
                }
            }).start();
        }
    }
}